package core.utils;

/**
 * @author wsz
 * @date 2021/11/12 17:21
 **/
public class HttpProtocolUtil {

    public static String getHttpHeader200(int length) {
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html \n" +
                "Content-Length: " + length + " \n" +
                "\r\n";
    }

    public static byte[] responseText(String content) {
        byte[] bytes = content.getBytes();
        String s = HttpProtocolUtil.getHttpHeader200(bytes.length) + content;
        return s.getBytes();
    }

    private static String str404 = "<h1>404 NOT FOUND</h1>";
    public static String getHttpHeader404( ) {
        return "HTTP/1.1 404 OK \n" +
                "Content-Type: text/html \n" +
                "Content-Length: " + str404.getBytes() + " \n" +
                "\r\n";
    }
}
